﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApp1.Models
{
    public class LanguageModel
    {
        public string Name { get; set; }
        public string LocalName { get; set; }

        static Dictionary<string, LanguageModel> nameDictionary = new Dictionary<string, LanguageModel>();

        public static List<LanguageModel> GetAllLanguages()
        {
            List<LanguageModel> results = new List<LanguageModel>();

            results.Add(new LanguageModel { Name = "English", LocalName = "English" });
            results.Add(new LanguageModel { Name = "Hindi", LocalName = "हिंदी" });
            results.Add(new LanguageModel { Name = "Tamil", LocalName = "தமிழ்" });
            results.Add(new LanguageModel { Name = "Telugu", LocalName = "తెలుగు" });
            results.Add(new LanguageModel { Name = "Kannada", LocalName = "ಕನ್ನಡ" });
            results.Add(new LanguageModel { Name = "Malayalam", LocalName = "മലയാളം" });
            results.Add(new LanguageModel { Name = "Marathi", LocalName = "मराठी" });
            results.Add(new LanguageModel { Name = "Gujarati", LocalName = "ગુજરાતી" });
            results.Add(new LanguageModel { Name = "Bengali", LocalName = "বাংলা" });

            nameDictionary.Clear();
            for (int i = 0; i < results.Count; i++)
            {
                nameDictionary.Add(results[i].Name.ToLower(), results[i]);
            }

            return results;
        }

        public static LanguageModel GetLanguageByLanguageName(string langugeName)
        {
            if (string.IsNullOrEmpty(langugeName))
                return null;

            if (nameDictionary.Count == 0)
                GetAllLanguages();

            langugeName = langugeName.ToLower();

            if (nameDictionary.Keys.Contains(langugeName) == false)
                return null;

            return nameDictionary[langugeName];
        }


    }


}